/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("cw_djlc_wljgwh_view",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.Finance.IServices;
using VOL.Core.Filters;
using Microsoft.AspNetCore.Authorization;
using VOL.Core.DBManager;
using System.Linq;
using VOL.Core.Extensions;
using System.Net;
using VOL.Core.Utilities;

namespace VOL.Finance.Controllers
{
    public partial class cw_djlc_wljgwh_viewController
    {
        private readonly Icw_djlc_wljgwh_viewService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public cw_djlc_wljgwh_viewController(
            Icw_djlc_wljgwh_viewService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        WebResponseContent webResponse = new WebResponseContent();
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult Update([FromBody] SaveModel saveModel)
        {

            var cw_djlc_wlzb_id = saveModel.MainData["cw_djlc_wlzb_id"];
            if (cw_djlc_wlzb_id.IsNullOrEmpty())
            {
                return Json(webResponse.Error("参数不能为空！"));
            }
            cw_djlc_wlzb wlzb = DBServerProvider.DbContext.Set<cw_djlc_wlzb>().Where(x => x.cw_djlc_wlzb_id == Guid.Parse(cw_djlc_wlzb_id.ToString())).FirstOrDefault();
            if (wlzb!=null)
            {
                if (wlzb.bomtype == 1)
                {
                    return Json(webResponse.Error("原始物料价格不能被修改！"));
                }
                else
                {
                    string materialnum = wlzb.materialnum;
                    string bomnumber = wlzb.bomnumber;
                    int count = DBServerProvider.DbContext.Set<cw_djlc_djzb>().Where(x => x.newmaterialnum == materialnum && x.stepid > 60 && x.newbomnumber ==bomnumber).ToList().Count();
                    if (count>0)
                    {
                        return Json(webResponse.Error("已定过价的物料不能被修改！"));
                    }
                }
            }

            return base.Update(saveModel);
        }

        
        [HttpPost, Route("GetPageData"), AllowAnonymous]
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult GetPageData([FromBody] PageDataOptions loadData)
        {
            return base.GetPageData(loadData);
        }

        [HttpPost, Route("Import"), AllowAnonymous]
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult Import(List<IFormFile> fileInput)
        {
            return base.Import(fileInput);
        }
    }
}
